package view;


import java.util.Arrays;

import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.aop.windows.TransactionalDialog;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.windows.WindowOwner;

import ApplicationModels.EmpleadoAppModel;
import Domain.Dia;
import Domain.Disponibilidad;

public class DisponibilidadWindow extends TransactionalDialog<EmpleadoAppModel> {

	public DisponibilidadWindow(WindowOwner parent, EmpleadoAppModel model) {

		super(parent, model);
	}

	@Override
	public void createMainTemplate(Panel mainPanel) {
		this.setTitle("Agregar Disponibilidad");

		super.createMainTemplate(mainPanel);
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		Panel vista = new Panel(mainPanel);
		vista.setLayout(new ColumnLayout(2));

		new Label(mainPanel).setText("Desde: ");
		new TextBox(mainPanel).bindValueToProperty("disponibilidadSeleccionada.desde");

		new Label(mainPanel).setText("Hasta: ");
		new TextBox(mainPanel).bindValueToProperty("disponibilidadSeleccionada.hasta");

		new Label(mainPanel).setText("Dia: ");

		Selector<Dia> dia = new Selector<Dia>(mainPanel);
		dia.setContents(Arrays.asList(Dia.values()), "nombre");
//		dia.bindItemsToProperty("disponibilidades");
		
		//Binding<ListBuilder<Disponibilidad>> itemsBinding = dia.bindItems( //
			//	new ObservableProperty(this.getModelObject().getDisponibilidades(), "empleado."));

	}

	@Override
	protected void addActions(Panel actionsPanel) {
		new Button(actionsPanel).setCaption("Agregar").onClick(
				new MessageSend(this.getModelObject()
						.getDisponibilidadSeleccionada(), "validar"));

		new Button(actionsPanel).setCaption("Cancelar").onClick(
				new MessageSend(this, "cancelar"));

	}

	public void cancelar() {

		this.getModelObject().setDisponibilidadSeleccionada(null);
	}

}
